<template>
  <eui-background type="common">
    <eui-navbar ref="EuiNavBar" title="打印削价签" :storeName="sUserStoreName" :storeId="sUserStore"
                :displayable="false" @onClickStore="clickStore" :closeCallback="closeCallback">
      <template v-slot:popupContent>
        <view class="custom-box">
          <view class="custom-menu">
            <eui-card-input
                type="radio"
                title="电子称码规则:"
                alignType="left"
                v-model="pluMode[0].value"
                @buttonClick="togglePluMode"
                :range="pluModeDict"
            />
          </view>
        </view>
      </template>
    </eui-navbar>
    <view class="top-view">
      <eui-search-bar ref="RdsSearchBar" v-model="searchText" placeholder="请输入商品条码、编码、PLU码或关键字"
                      leftIcon="icon-saoyisao"
                      @confirm="searchConfirm" @leftIconClick="scanCode" radius="30" :showFilterIcon="false"/>
    </view>
    <view class="main-info" v-if="!isOpenGdsList">
      <scroll-view scroll-y="true" style="max-height:140px;">
        <view class="m-list-top" v-if="gdsData.c_gcode">
          <eui-text :value="gdsData.c_gcode" type="titlename" title="商品:" :name="gdsData.c_name" occupy/>
          <eui-text :value="gdsData.c_barcode" type="name" title="主条码:"/>
          <eui-text :value="gdsData.c_pluno" type="name" title="PLU码:"/>
          <eui-text :value="gdsData.c_adno_level" type="titlename"
                    :name="getRelatedName('rdsDeparts', gdsData.c_adno_level)"
                    title="部门:"/>
          <!--              <rds-text :value="gdsData.c_model" :name="gdsData.c_basic_unit" type="slash" title="规格/单位:"/>-->
          <eui-text :value="(gdsData.c_od_day || '') + getDictName('保质期单位', gdsData.c_od_unit)" type="name"
                    title="保质期:"/>
          <!--              <rds-text :value="gdsData.c_produce" type="name" title="产地:"/>-->
          <eui-text :value="gdsData.c_basic_unit" type="name" title="单位:"/>
          <eui-text :value="getDictName('商品类型', gdsData.c_type)" type="name" title="商品类型:"/>
        </view>
        <eui-list-template type="list" :value="gdsstorePriceData" :title="false"
                           templateTitle="" :isBottem="false" @onRefresh="fetchStorePrice"
                           note="暂无机构商品价格">
          <template v-slot:list="item">
            <eui-text v-if="gdsstorePriceData.length > 1" :value="item.c_store_id" type="titlename"
                      :name="getRelatedName('rdsStores', item.c_store_id)"
                      title="机构:"/>
            <eui-text v-if="gdsstorePriceData.length > 1" :value="item.c_barcode" type="name" title="条码:"/>
            <eui-text v-if="gdsstorePriceData.length > 1" :value="getDictName('价格类型', item.c_is_barcode)"
                      type="name" title="价格类型:"/>
            <eui-text :value="item.c_price" type="price" title="零售价:"/>
            <eui-text v-if="item.c_price_mem > 0" :value="item.c_price_mem" type="price" title="会员价:"/>
            <eui-text v-if="item.c_price_disc > 0" :value="item.c_price_disc" type="price" title="促销价:"/>
          </template>
        </eui-list-template>
      </scroll-view>
      <view v-if="gdsstorePriceData.length > 0"  >
        <view v-if="isShowSwitch">
          <view class="switch-tab" v-if="sysConfig.pluDiscount.length > 0">
            <view v-for="(item, index) in sysConfig.pluDiscount"
                  :class="formData.cutting == item.c_id ? 'active' : 'normal'" @click="()=>swichTab(item.c_id)" :key="index">
              {{ item.c_name }}
            </view>
          </view>
          <view class="switch-tab" v-else>
            <view :class="formData.cutting == '30' ? 'active' : 'normal'" @click="()=>swichTab('30')">3折</view>
            <view :class="formData.cutting == '50' ? 'active' : 'normal'" @click="()=>swichTab('50')">5折</view>
            <view :class="formData.cutting == '70' ? 'active' : 'normal'" @click="()=>swichTab('70')">7折</view>
            <view :class="formData.cutting == '90' ? 'active' : 'normal'" @click="()=>swichTab('90')">9折</view>
          </view>
          <eui-card-input v-model="formData.newprice" :title="newPriceTitle" type="number" placeholder="请选择折扣"
                          :displayable="true" required="true"/>
        </view>
        <view v-else>
          <eui-card-input ref="RefCutting" v-model="formData.cutting" title="折扣率(1-99)" type="number" placeholder="请输入折扣率" maxlength="2"
                          required="true" @confirm="onBlurCutting" isBlur/>
          <eui-card-input ref="RefNewprice" v-model="formData.newprice" :title="newPriceTitle" type="digit" placeholder="请输入新售价"
                          required="true" @confirm="onBlurNewprice" isBlur/>
        </view>
          <eui-card-input v-model="formData.c_dt" title="截止日期" type="date" placeholder="请选择截止日期"
                          :displayable="displayable" required="true"/>
          <eui-card-input v-model="formData.number" title="价签个数" type="number2" placeholder="新输入价签个数"
                          :displayable="displayable" maxlength="4" required="true" :isBlur="true" id="number" />
          <eui-card-input
              v-model="gdsLabelName"
              title="打印模版"
              placeholder="请选择打印模版"
              type="textname"
              rifhtIcon
              required="true"
              displayable
              rightIconType="right"
              @iconClick="clickRight('gdsLabel')"
          ></eui-card-input>
          <eui-card-input
              v-model="printerName"
              title="打印机"
              placeholder="请选择打印机"
              type="textname"
              rifhtIcon
              required="true"
              displayable
              rightIconType="right"
              @iconClick="clickRight('printer')"
          ></eui-card-input>

      </view>
    </view>
    <view class="virtual_footer" v-if="!isOpenGdsList && gdsstorePriceData.length > 0">
      <eui-button :title="isShowSwitch ? '自定义折扣' : '系统折扣'" @click="cutBtnClick" :disabled="gdsstorePriceData.length === 0" type="base2" />
      <eui-button title="打印削价签" @click="buttonClick"
                  :disabled="gdsstorePriceData.length === 0 || printerName == '' || formData.newprice == ''"/>
    </view>
    <view class="virtual_head" v-if="isOpenGdsList">
      <text class="cell_color_code" style="flex: 0 0 18%">编码</text>
      <text class="cell_color_code" style="flex: 0 0 50%">商品(条码)</text>
      <text class="cell_color_code flex_w_auto">部门</text>
    </view>
    <view class="footer" v-if="isOpenGdsList">
      <eui-virtual-list :origList="gdsList" type="list2"
                        @onRefresh="fetchGds"
                        @lower="templateLower"
                        @upper="templateUpper"
                        refresher="true">
        <template v-slot:list="scope">
          <view class="itemClickView" @tap="onTapGoods(scope.c_gcode)">
            <view class="list_cell_item cell_color_id" style="flex: 0 0 18%">{{ scope.c_gcode }}</view>
            <view class="list_cell_item" style="flex: 0 0 50%">
              <view>{{ scope.c_name }}</view>
              <view class="cell_color_code">{{ scope.c_barcode }}</view>
            </view>
            <view class="list_cell_item cell_color_code flex_w_auto">[{{ scope.c_adno_level }}]{{
                scope.c_adname
              }}
            </view>
          </view>
        </template>
      </eui-virtual-list>
    </view>
  </eui-background>
</template>

<script setup type="ts">
import { computed, ref } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import dateRangUtil from '@/common/dateRangUtil';
import Enjoy from '@/common/enjoy';
import service from '@/common/service';
import { clearRdsLocalStorage, getRdsSysConfig, init } from '@/hooks/init';
import {getRdsUrl, rdsRequest,} from '@/hooks/rdsServices';
import { useMainStore } from '@/store/modules/store';
import { useLoginStore } from '@/store/modules/useLoginStore';
import { clearBcmLocalStorage } from '../../../hooks/bcmInit';
import { getGstatus } from '../../../hooks/useGdsStatus';
import { getDictList, getDictName, getRelatedName } from '../components/RelatedName.js';
import jpPrinter from '../../../common/gprint/tscNew';

const rdsUrl = getRdsUrl();
const mainStore = useMainStore();
const LoginStore = useLoginStore();

// MARK: - 响应式的数据
const sUserStore = ref(''); // 用户默认机构编码
const sUserStoreName = ref(''); // 用户默认机构名称
const sUser = ref(''); // 当前用户编码

const RdsSearchBar = ref(null);

const formData = ref({
  newprice: '',
  c_dt: dateRangUtil.getLastToday()[0],
  cutting: '',
  number: 1,
});

const EuiNavBar = ref(null);
const searchText = ref('');
const searchTextOrig = ref(''); // 原始录入码
const extendNavBarMenus = ref([]);
const displayable = ref(false); // true允许页面编辑

const isShowSwitch = ref(true); // true:显示系统折扣，false:自定义折扣
const RefCutting = ref(null); // 自定义折扣
const RefNewprice = ref(null); // 自定义新售价
const isWeightPrice = ref(false); // true: 重量+金额； false: 金额+重量

const pluMode = ref([{
  text: '金额-重量',
  value: '0'
}]);
const pluModeDict = ref([{
  text: '金额-重量',
  value: '0'
},{
  text: '重量-金额',
  value: '1'
}]); // “金额-重量” 0 or "重量-金额" 1,默认覆盖 0

// 系统参数，字典
const sysConfig = ref({
  pluLEN6: 0, // plu默认5位,0-> 否，1->是
  pluFLAG: [], // 生鲜条码前缀数组
  pluDiscount: [], // 削价可选折扣
  SYSCFG_GDSLENGTH_MIN: 5, // 商品编码长度 6, PLU 编码规则，默认5
  gStatusSale: [],
});

// plu商品信息
const isPlu = ref(false);
const pluData = ref({
  plu_price: '',
  plu_weight: '',
});

// 接口返回数据
const gdsData = ref({
  c_gcode: '',
  c_name: '',
  c_barcode: '',
  c_price: '',
  c_model: '',
  c_plu_type: '',
  c_od_day: '',
  c_od_unit: '',
  c_type: '',
  c_status: '',
});
// const gdsData = ref({
//   "c_tenant_id": "8",
//   "c_guid": "44DDBE08-3BA1-4570-97C9-3F0D6100B9CB",
//   "c_gcode": "0018376",
//   "c_barcode": "2001440134735",
//   "c_pycode": "",
//   "c_level": "1",
//   "c_spu_code": "",
//   "c_plu_type": "1",
//   "c_pluno": "03207",
//   "c_ccode": "1101010301",
//   "c_allude_gcode": "",
//   "c_name": "黄皮椒",
//   "c_name_en": "",
//   "c_short_name": "",
//   "c_short_name_en": "",
//   "c_basic_unit": "kg",
//   "c_model": "",
//   "c_produce": "广东",
//   "c_grade": "1",
//   "c_label_type": "1",
//   "c_introduce_status": "1",
//   "c_buy_userno": "",
//   "c_bcode": "0000",
//   "c_od_day": 2,
//   "c_od_unit": "D",
//   "c_timeliness": "0",
//   "c_process_type": "0",
//   "c_service_type": "",
//   "c_third_ccode": "",
//   "c_gds_tax_code": "",
//   "c_u_level": null,
//   "c_cat_group": "",
//   "c_is_group": "0",
//   "c_gdsclass_type": "0",
//   "c_lost_rate": 0.0000,
//   "c_cons_tax_rate": 0.0000,
//   "c_au_userno": "6002",
//   "c_global_no": "",
//   "c_modify_userno": "6002",
//   "c_modify_dt": "2024-10-28 14:27:01.980",
//   "c_comment": "",
//   "c_od_warning_day": null,
//   "c_store_id": "11013",
//   "c_adno": "1101",
//   "c_status": "2",
//   "c_ctrlno": "ZEPAB",
//   "c_price_sens": "N",
//   "c_dt": "2024-10-28 14:27:02.630",
//   "c_type": "1",
//   "c_provider": "1101",
//   "c_con_type": "1",
//   "c_order_enlarge": 1.00,
//   "c_order_content": 1.000,
//   "c_order_unit": "kg",
//   "c_distr_content": 1.000,
//   "c_distr_unit": "kg",
//   "c_unpack": "0",
//   "c_disuse_date": null,
//   "c_introduce_date": "2024-10-28 14:27:02.027",
//   "c_tax_rate": 0.0000,
//   "c_opl_prohibit": "0",
//   "c_uplmt_day": 0,
//   "c_dnlmt_day": 0,
//   "c_n_min_order": 0.000,
//   "c_dnlmt_number": 0,
//   "c_n_min": 0.000,
//   "c_n_max": 0.000,
//   "c_pp_reason": null,
//   "c_pp_restore_date": null,
//   "c_property_group": "",
//   "c_sn_method": "0",
//   "c_service_owner": "1",
//   "c_cat_group_name": null,
//   "c_cat_group_name_en": null,
//   "c_price": 1.00,
//   "c_price_mem": 0.0000,
//   "c_min_price": 0.00,
//   "c_advice_price": 0.00,
//   "c_wprice": 0.0000,
//   "c_cname": "茄类",
//   "c_cname_en": null,
//   "c_bname": "万民",
//   "c_bname_en": "",
//   "c_adname": "蔬菜课",
//   "c_adname_en": null,
//   "c_buy_username": null,
//   "c_adno_level": "1101",
//   "c_abc": "C",
//   "c_dms": 0.000,
//   "c_sale_frequency": "2",
//   "c_abc_rank": 0,
//   "c_pdms": 0.000,
//   "c_test_day": 90,
//   "c_test_plan": 0.0000,
//   "c_first_order_dt": null,
//   "c_rec_date": null,
//   "c_firstsale_dt": null,
//   "c_number1": null,
//   "c_number2": null,
//   "c_number3": null,
//   "c_number4": null,
//   "c_text1": null,
//   "c_text2": null,
//   "c_text3": null,
//   "c_text4": null,
//   "c_text5": null,
//   "c_text6": null,
//   "c_text7": null,
//   "c_text8": null
// })

const gdsstorePriceData = ref([]);
// const gdsstorePriceData = ref([{
//   "c_gname": "黄皮椒",
//   "c_gname_en": "",
//   "c_tenant_id": "8",
//   "c_store_id": "11013",
//   "c_gcode": "0018376",
//   "c_barcode": "",
//   "c_price": 1.00,
//   "c_price_mem": 0.0000,
//   "c_wprice": 0.0000,
//   "c_min_price": 0.00,
//   "c_advice_price": 0.00,
//   "c_modify_dt_p": null,
//   "c_mk_dt": "2024-10-28 14:27:02.660",
//   "c_mk_userno": "6002",
//   "c_modify_dt": null,
//   "c_modify_userno": null,
//   "c_note": "",
//   "c_is_barcode": "G",
//   "c_price_disc": null,
//   "c_price_rate": null,
//   "c_price_mem_disc": null,
//   "c_price_mem_rate": null
// }])

// 模糊搜索商品列表
const gdsList = ref([]);
const CurrentPage = ref(1);  //第几页
const PageSize = ref(20);  //每页10条
const RowsCount = ref(0);  //总条数
const PageCount = ref(1);  //总页
// 设备id
const connId = ref(''); // 打印机id = printerId
const cmd = ref({});
const ISsenBleLabel = ref(false);
const selectType = ref('');
const printerId = ref(''); // 打印机
const printerName = ref('');
const gdsLabel = ref('');
const gdsLabelName = ref('');
const IsUserDR = ref(false);
const currDev = ref({});

// MARK: - 计算属性
const isOpenGdsList = computed(() => {
  return gdsList.value.length > 0;
});

const newPriceTitle = computed(() => {
  return isPlu.value
      ? '原价[' + pluData.value.plu_price + ']' + (gdsData.value.c_plu_type == '1' ? '重量' : '件数') + '[' + pluData.value.plu_weight + ']/新售价'
      : '新售价';
});

// 监听器

//  MARK: - 页面生命周期: 页面加载
onLoad(async () => {
  await init();
  await getSysConfig();
  await setDefault();
  // 控制光标跳转
  setTimeout(() => {
    RdsSearchBar.value.clear();
  }, 100);
});

// MARK: - 切换机构事件
const clickStore = () => {
  let parms = Enjoy.GetDialogParms();
  parms.CallBack = SelectionChanged;
  parms.SelectionType = '机构选择';
  parms.WhereList = [{'c_col': 'c_type', 'c_oper': '包含', 'c_value': '2', 'c_logic': '而且'}];
  parms.SelectedItems = sUserStore.value;
  Enjoy.OpenDialog(parms);
};

// MARK: - 设置默认值
const setDefault = () => {
  const {loginInfo} = mainStore;
  sUser.value = loginInfo.sUser;
  // 机构类型 2-分店
  if (loginInfo.sUserStoreHier != '2') {
    clickStore()
    return
  }
  sUserStore.value = loginInfo.sUserStore;
  sUserStoreName.value = loginInfo.sUserStoreName;
};

// MARK: - 获取系统参数、字典
const getSysConfig = async () => {
  // 削价可选折扣, 并按 c_id 正序重新排列
  sysConfig.value.pluDiscount = (await getDictList('削价签折扣')).sort((a,b) => a.c_id - b.c_id);
  // 是否允许手工修改折后价

  // 管易通条码信息变更单削价码默认失效天数

  // 管e通削价条码新售价计算时四舍五入的单位

  // 管e通打印削价码价格为零时的控制办法

  // 管易通不需要显示成本价、进价及相关金额的功能模块

  // 商品削价二维码方式的内容前缀

  // 生鲜条码前缀数组 pluFLAG
  const flag1 = await getRdsSysConfig('条码规则参数', '含金额重量生鲜条码前缀');
  if (flag1) {
    if (flag1.indexOf(',') > -1) {
      flag1.split(',').forEach(x => {
        if (Number(x) > 0) sysConfig.value.pluFLAG.push(x);
      })
    } else {
      if (Number(flag1) > 0) sysConfig.value.pluFLAG.push(flag1);
    }
  }

  // 获取 系统配置 系统内商品编码长度
  const SYSCFG_GDSLENGTH = await getRdsSysConfig('采购管理参数', '系统内商品编码长度')
  if ( SYSCFG_GDSLENGTH && SYSCFG_GDSLENGTH != '') {
    const gdsMinLength = SYSCFG_GDSLENGTH.split(',').sort((a, b) => Number(a) - Number(b))[0]
    sysConfig.value.SYSCFG_GDSLENGTH_MIN =  gdsMinLength < sysConfig.value.SYSCFG_GDSLENGTH_MIN
        ? gdsMinLength
        : sysConfig.value.SYSCFG_GDSLENGTH_MIN;
  }

  // 获取商品状态（可售卖）
  const gStatus = await getGstatus();
  if (gStatus.gstatus && gStatus.gstatus.length > 0) {
    sysConfig.value.gStatusSale = gStatus.gstatus.filter(f => f.c_is_sale !== '0').map(item => item.c_id);
  }
};

// MARK: - 模糊查找商品列表
const fetchGds = async () => {
  service.enjoyShowLoading('正在加载...');
  const req = {
    IsNotPage: false,
    CurrentPage: CurrentPage.value,
    PageSize: PageSize.value,
    UserNo: sUser.value,
    WhereList: [
      {c_col: 'c_pycode', c_oper: '左相似', c_value: searchText.value, c_logic: '或者'},
      {c_col: 'c_name', c_oper: '相似', c_value: searchText.value, c_logic: '而且'},
      {c_col: 'c_store_id', c_oper: '等于', c_value: sUserStore.value, c_logic: '而且'},
    ],
  };
  const result = await rdsRequest(rdsUrl.bcApi, '商品信息查询', 'EnjoyQueryList', req, '');
  if (result.ReturnObject.length > 0) {
    gdsList.value = result.ReturnObject;
  } else {
    gdsList.value = [];
    uni.showToast({
      duration: 2000,
      icon: 'none',
      title: '暂无数据',
      mask: true,
    });
  }
  service.enjoyHideLoading();
};

// 点击商品列表项
const onTapGoods = async (code) => {
  await searchConfirm({value: code});
  gdsList.value = [];
};

// 获取商品详情信息
const getData = async () => {
  if (!searchText.value) {
    RdsSearchBar.value.clear();
    return false;
  };
  service.enjoyShowLoading('正在加载...');
  const req = {
    CurrentPage: 1,
    IsNotPage: true,
    PageSize: 100,
    WhereList: [
      {c_col: 'c_gcode', c_oper: '等于', c_value: searchText.value, c_logic: '而且'},
      {c_col: 'c_store_id', c_oper: '等于', c_value: sUserStore.value, c_logic: '而且'},
    ],
  };
  const result = await rdsRequest(rdsUrl.bcApi, '商品信息查询', 'FetchUniversal', req, '');
  if (result.ds.length > 0) {
    // 商品状态是否可售卖判断
    if (sysConfig.value.gStatusSale.length > 0 && !sysConfig.value.gStatusSale.includes(result.ds[0].c_status)) {
      uni.showToast({
        duration: 2000,
        icon: 'none',
        title: `[${result.ds[0].c_gcode}]${result.ds[0].c_name}，商品不可销售！`,
      });
      cleanGdsInfo();
      return false
    }
    gdsData.value = result.ds[0];
    await fetchStorePrice(); // 价格信息
  } else {
    uni.showToast({
      duration: 2000,
      icon: 'none',
      title: '暂无数据',
      mask: true,
    });
    RdsSearchBar.value.clear();
  }
  service.enjoyHideLoading();
};

// 检查是否PLU
const checkPrefixMatch = (prefixes, barcode) => {
  // 遍历前缀数组中的每一个前缀
  for (let i = 0; i < prefixes.length; i++) {
    // 如果条码以当前前缀开头，返回索引
    if (barcode.startsWith(prefixes[i])) {
      return i;
    }
  }
  return -1;
};

// 识别称重商品
const checkPluType = (code) => {
  const {pluLEN6, pluFLAG} = sysConfig.value;
  const fIndex = checkPrefixMatch(pluFLAG, code);
  if (fIndex > -1) {
    // 根据系统参数：是否允许PLU码为6位 ，默认5位
    const LENGTH_PLU = pluLEN6 == 0 ? 5 : 6;
    // 获取电子称码中的plu码
    const c_gcode = code.substring(pluFLAG[fIndex].length, pluFLAG[fIndex].length + LENGTH_PLU);

    // 设置搜索文本和PLU状态
    searchText.value = c_gcode;
    isPlu.value = true;

    if (code.length === 18) {
      // 21 03256 00283 00474 1
      if (isWeightPrice.value) {
        // 重量 + 金额
        const _plu_weight = code.substring(
            pluFLAG[fIndex].length + LENGTH_PLU,
            pluFLAG[fIndex].length + LENGTH_PLU + 5,
        );
        pluData.value.plu_weight = parseFloat(_plu_weight.slice(0, 2) + '.' + _plu_weight.slice(2)); // 重量长度5，小数位3

        const _plu_price = code.substring(
            pluFLAG[fIndex].length + LENGTH_PLU + 5,
            pluFLAG[fIndex].length + LENGTH_PLU + 5 + 5,
        );
        pluData.value.plu_price = parseFloat(_plu_price.slice(0, 3) + '.' + _plu_price.slice(3)); // 金额长度5，小数位2
      } else {
        // 金额 + 重量
        const  _plu_price = code.substring(
            pluFLAG[fIndex].length + LENGTH_PLU,
            pluFLAG[fIndex].length + LENGTH_PLU + 5,
        );
        pluData.value.plu_price = parseFloat(_plu_price.slice(0, 3) + '.' + _plu_price.slice(3)); // 重量长度5，小数位2

        const _plu_weight = code.substring(
            pluFLAG[fIndex].length + LENGTH_PLU + 5,
            pluFLAG[fIndex].length + LENGTH_PLU + 5 + 5,
        );
        pluData.value.plu_weight = parseFloat(_plu_weight.slice(0, 2) + '.' + _plu_weight.slice(2)); // 金额长度5，小数位3
      }

    }
    if (code.length === 13) {
      // 例如： 22 03141 00796 1
      const _plu_price = code.substring(
          pluFLAG[fIndex].length + LENGTH_PLU,
          pluFLAG[fIndex].length + LENGTH_PLU + 5,
      );
      pluData.value.plu_price = parseFloat(_plu_price.slice(0, 3) + '.' + _plu_price.slice(3)); // 金额长度5，小数位2
    }

  } else {
    isPlu.value = false;
    pluData.value.plu_price = 0;
    pluData.value.plu_weight = '0.001'; // 默认重量
  }
};

// MARK: - 获取商品分店价格
const fetchStorePrice = async () => {
  service.enjoyShowLoading('正在加载...');
  const req = {
    WhereList: [
      {c_col: 'c_gcode', c_oper: '等于', c_value: searchText.value, c_logic: '而且'},
      {c_col: 'c_store_id', c_oper: '等于', c_value: sUserStore.value, c_logic: '而且'},
    ],
  };
  const result = await rdsRequest(rdsUrl.bcApi, '商品信息查询', 'FetchStorePrice', req, '');
  if (result.ds.length > 0) {
    gdsstorePriceData.value = result.ds;
    // 如果称重商品且称码长度13需反算重量
    if(isPlu.value && searchTextOrig.value.length === 13) {
      // 促销价 > 原售价
      const { c_price_disc, c_price  } = result.ds[0];
      const _c_price = c_price_disc || c_price || 1;
      const _plu_price = pluData.value.plu_price || 1;
      const _plu_weight = Math.round( _plu_price / _c_price * 1000) / 1000;
      pluData.value.plu_weight = _plu_weight
    }
  } else {
    gdsstorePriceData.value = [];
  }
  service.enjoyHideLoading();
};

// MARK: - 弹框 回调方法：切换机构/打印模板
const SelectionChanged = async (event) => {
  if (event.SelectionType == '机构选择') {
    // 更新机构信息
    sUserStoreName.value = event.BackParms.Value;
    sUserStore.value = event.BackParms.Key;
    // 按新条件获取数据
    formData.value.c_store_id = sUserStore.value;
    // 按新条件获取数据
    await getData();
  }
  if (event.type == 'gdsLabel') {
    gdsLabel.value = event.c_guid;
    gdsLabelName.value = event.c_name;
  }
  if (event.type == 'printer') {
    printerName.value = `${event.name}(${event.deviceId})`;
    printerId.value = event.deviceId;
    connId.value = event.deviceId;
    currDev.value = event;
    // plus.storage.setItem('defaultBluetooch', this.printerId);
    // plus.storage.setItem('defaultBluetoochName', this.printerName);
    // plus.storage.setItem('defaultBuleDev', this.currDev);
  }
};

// MARK: - 扫商
const searchConfirm = async (e) => {
  const code = e.value;
  if (!code) {
    gdsList.value = [];
    return;
  }
  searchTextOrig.value = code;
  searchText.value = code;
  // 支持名称或拼音码搜索
  if (code.length < sysConfig.value.SYSCFG_GDSLENGTH_MIN || isNaN(Number(code))) {
    await fetchGds();
  } else {
    checkPluType(code);
    await getData();
    // 清空折扣选择和新售价
    formData.value.newprice = ''
    formData.value.cutting = ''
  }
};

// MARK: - 点击扫描图标跳转打开摄像头
const scanCode = () => {
  uni.scanCode({
    success: function (res) {
      if (res.result != '' && res.result != undefined && res.result != null) {
        searchConfirm({value: res.result})
      }
    },
  });
};

// 列表项点击跳转到详情页面
const listItemClick = (e, c_gcode = '') => {
  uni.navigateTo({
    url: './detail?c_id=' + e.c_id + '&c_gcode=' + c_gcode + '&c_store_id=' + e.c_store_id,
  });
};

// 按钮事件监听
const buttonClick = async () => {
    await print();
};

// 选择折扣
const swichTab = (e) => {
  if (gdsstorePriceData.value.length == 0) {
    formData.value.cutting = '';
    formData.value.newprice = '';
  } else {
    formData.value.cutting = e;
    formData.value.newprice = isPlu.value
        ? (pluData.value.plu_price * formData.value.cutting * 0.01).toFixed(2)
        : ((gdsstorePriceData.value[0].c_price_disc || gdsstorePriceData.value[0].c_price )* formData.value.cutting * 0.01).toFixed(2);
  }
};

// 打印
const print = async () => {
  uni.showModal({
    title: '确认打印',
    content: ``,
    success(res) {
      if (res.confirm) {
        getPrintCommand(formData.value, function (gds, command) {
          if (command != undefined) {
            cmd.value = command;
            // 执行打印逻辑
            searchBle();
          }
        });
      }
    },
  });
};

// MARK: - 获取打印指令
const getPrintCommand = async (data, callback) => {
  service.enjoyShowLoading('正在加载...');
  const {c_gcode, c_name, c_barcode, c_model, c_plu_type} = gdsData.value;
  const { c_price, c_price_disc } = gdsstorePriceData.value[0]
  const {newprice, c_dt, number, cutting} = formData.value;

  if (isPlu.value && c_plu_type != '1') {
    pluData.value.plu_weight = (pluData.value.plu_weight || 1) * 0.001;
  }

  const {plu_price, plu_weight} = pluData.value;
  const req = {
    FormatGuid: gdsLabel.value,
    StoreId: sUserStore.value,
    Userno: sUser.value,
    Gcode: c_gcode,
    Barcode: c_barcode,
    OrigPrice: isPlu.value ? plu_price : (c_price_disc || c_price),
    Price: newprice,
    PrintNum: number,
    Reason: '',
    Amount: isPlu.value ? plu_weight : '0.001',
    Model: c_model,
    Gname: c_name,
    dInputAmount: newprice,
    Discount: parseFloat((cutting / 10).toFixed(1)) + '折',
    EndDt: c_dt + ' 23:59',
  };
  const result = await rdsRequest(rdsUrl.apiApi, '管易通价签打印', 'GetPrintCommand', req, '');
  // const result = {
  //   "Amount": 0,
  //   "Command": null,
  //   "Barcode": null,
  //   "sErrMsg": null,
  //   "IsUserDR": true,
  //   "PrintDRlst": [
  //     {
  //       "Amount": 10.8,
  //       "Command": "33,32,48,32,50,48,48,32,50,48,48,32,51,50,48,32,49,13,10,80,65,71,69,45,87,73,68,84,72,32,52,56,48,13,10,83,69,84,83,80,32,48,13,10,76,69,70,84,13,10,84,69,88,84,32,50,32,49,50,32,48,32,50,50,52,32,180,242,211,161,202,177,188,228,163,186,13,10,76,69,70,84,13,10,76,69,70,84,13,10,84,69,88,84,32,50,32,49,50,32,49,52,52,32,50,50,52,32,50,48,50,52,45,49,48,45,49,53,32,48,50,58,48,48,13,10,76,69,70,84,13,10,76,69,70,84,13,10,84,69,88,84,32,50,32,49,50,32,51,51,54,32,57,54,32,213,219,13,10,76,69,70,84,13,10,76,69,70,84,13,10,84,69,88,84,32,50,32,49,50,32,50,51,50,32,49,55,54,32,49,48,46,56,48,13,10,76,69,70,84,13,10,76,69,70,84,13,10,84,69,88,84,32,50,32,49,50,32,50,51,50,32,49,51,54,32,49,50,13,10,76,69,70,84,13,10,83,69,84,77,65,71,32,49,32,49,13,10,76,69,70,84,13,10,84,69,88,84,32,52,32,50,48,32,48,32,49,54,32,76,81,178,226,202,212,201,204,198,183,45,49,13,10,76,69,70,84,13,10,83,69,84,77,65,71,32,48,32,48,13,10,66,32,81,82,32,48,32,55,50,32,77,32,50,32,85,32,53,13,10,77,65,44,54,51,50,52,49,48,49,53,48,48,48,48,48,53,48,48,48,48,53,50,55,48,49,50,48,48,48,49,48,56,48,48,48,48,48,49,50,52,49,48,49,53,50,51,53,57,48,51,13,10,69,78,68,81,82,13,10,76,69,70,84,13,10,84,69,88,84,32,50,32,49,50,32,51,49,50,32,57,54,32,57,13,10,76,69,70,84,13,10,76,69,70,84,13,10,84,69,88,84,32,50,32,49,50,32,51,51,54,32,49,51,54,32,212,170,13,10,76,69,70,84,13,10,76,69,70,84,13,10,84,69,88,84,32,50,32,49,50,32,51,51,54,32,49,55,54,32,212,170,13,10,76,69,70,84,13,10,76,69,70,84,13,10,84,69,88,84,32,50,32,49,50,32,49,52,52,32,49,51,54,32,212,173,215,220,182,238,163,186,13,10,76,69,70,84,13,10,76,69,70,84,13,10,84,69,88,84,32,50,32,49,50,32,49,52,52,32,49,55,54,32,207,214,215,220,182,238,163,186,13,10,76,69,70,84,13,10,83,69,84,77,65,71,32,49,32,49,13,10,76,69,70,84,13,10,84,69,88,84,32,52,32,50,48,32,49,52,52,32,56,48,32,45,49,48,46,48,48,37,13,10,76,69,70,84,13,10,83,69,84,77,65,71,32,48,32,48,13,10,76,69,70,84,13,10,84,69,88,84,32,50,32,49,50,32,48,32,50,53,54,32,189,216,214,185,211,208,208,167,198,218,163,186,13,10,76,69,70,84,13,10,76,69,70,84,13,10,84,69,88,84,32,50,32,49,50,32,49,52,52,32,50,53,54,32,50,48,50,52,45,49,48,45,49,53,32,50,51,58,53,57,13,10,76,69,70,84,13,10,76,69,70,84,13,10,84,69,88,84,32,53,53,32,56,32,56,32,50,57,54,32,45,45,45,45,45,45,32,189,225,213,203,202,177,201,168,195,232,201,207,183,189,182,254,206,172,194,235,207,237,213,219,191,219,188,219,32,45,45,45,45,45,45,13,10,76,69,70,84,13,10,70,79,82,77,13,10,80,82,73,78,84,13,10,",
  //       "Barcode": "632410150000050000527012000108000001241015235903",
  //       "sErrMsg": null
  //     }
  //   ]
  // }
  if (result) {
    IsUserDR.value = result.IsUserDR;
    callback(data, result);
  }
  service.enjoyHideLoading();
};

// 初始化蓝牙模块
const searchBle = () => {
  service.enjoyShowLoading('正在打印...');
  // #ifdef APP-PLUS
  plus.bluetooth.openBluetoothAdapter({
    success: function () {
      service.enjoyHideLoading();
      if (connId.value == '') {
        plus.bluetooth.onBluetoothDeviceFound(function (devices) {
          const re = JSON.parse(JSON.stringify(devices));
          if (re && re.devices) {
            for (let i = 0; i < re.devices.length; i++) {
              if (re.devices[i].name != '') {
                if (re.devices[i].deviceId == printerId.value) {
                  onConn(re.devices[i]);
                  stopFindBule();
                }
              }
            }
          }
        });
      } else {
        const devices = {
          deviceId: connId.value,
          name: printerName.value,
        };
        onConn(devices);
        getBLEServices(connId.value);
      }
      plus.bluetooth.getBluetoothAdapterState({
        success: function (res) {
          if (res.available) {
            if (res.discovering) {
              stopFindBule();
            }
            // 搜索蓝牙
            onDevice();
          }
        },
      });
    },
    fail: function (e) {
      uni.showToast({
        duration: 3500,
        icon: 'none',
        title: '打印失败，原因：' + JSON.stringify(e),
      });
      service.enjoyHideLoading();
    },
  });
  // #endif
};


//
const onConn = (item) => {
  var that = this;
  var deviceId = item.deviceId;
  // #ifdef APP-PLUS
  plus.bluetooth.getConnectedBluetoothDevices({
    success: function (e) {
      var devices = JSON.parse(JSON.stringify(e.devices));
      let bIsCon = false; //是否已连接
      //判断设备是否为连接状态
      for (var i = 0; i < devices.length; i++) {
        if (devices[i].deviceId == deviceId) {
          getBLEServices(deviceId);
          bIsCon = true;
          break;
        }
      }
      //若设备是未连接状态，则创建连接
      if (bIsCon == false) {
        plus.bluetooth.createBLEConnection({
          deviceId: deviceId,
          success: function (e) {
            connId.value = deviceId;
            getBLEServices(deviceId);
            //onConn(item);
            //首次连接成功后，从头走一遍，否则可能会失败，未查到原因。
            //getSumbit();
          },
          fail: function (e) {
            closeBluetoothAdapter(searchBle);
          },
        });
      }
    },
    fail: function (e) {
      uni.showToast({
        duration: 3500,
        icon: 'none',
        title: '连接设备失败，请检查设备是否开启!'
      });
    },
  });
  // #endif
}
//
const stopFindBule = () => {
  // #ifdef APP-PLUS
  plus.bluetooth.stopBluetoothDevicesDiscovery({
    success: function (e) {
    },
    fail: function (e) {
      closeBluetoothAdapter();
    },
  });
  // #endif
}
// MARK: - 蓝牙打印
const getBLEServices = (_deviceId) => {
  var that = this;
  var deviceId = _deviceId;
  // #ifdef APP-PLUS
  plus.bluetooth.getBLEDeviceServices({
    deviceId: deviceId,
    success: function (res) {
      // console.log('getBLEServices---------------------------', res);
      var services = JSON.parse(JSON.stringify(res.services));
      var s1 = 0;
      if (services && services.length > 0) {
        for (var s = 0; s < services.length; s++) {
          var serviceId1 = services[s]['uuid'];
          plus.bluetooth.getBLEDeviceCharacteristics({
            // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
            deviceId: deviceId,
            // 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
            serviceId: serviceId1,
            success(e) {
              // console.log('--------------------getBLEDeviceCharacteristics: ', e);
              var re = JSON.parse(JSON.stringify(e));
              for (var c = 0; c < re.characteristics.length; c++) {
                if (re.characteristics[c].properties.write == true) {
                  //const target = {
                  //   "uuid": "49535343-8841-43F4-A8D4-ECBE34729BB3",
                  //       "properties": {
                  //     "read": false,
                  //         "write": true,
                  //         "notify": false,
                  //         "indicate": false
                  //   }
                  // }
                  var uuid = re.characteristics[c].uuid;
                  currDev.value.deviceId = deviceId;
                  currDev.value.services = {
                    serviceId: services[s1].uuid,
                    characteristicId: uuid,
                  };
                  senBleLabel();
                  break;
                }
              }
              s1++;
            },
            fail: function (err) {
              // console.log("err: " + JSON.stringify(err));
            },
          });
        }
      } else {
        //console.log('未获取到相关出蓝牙服务');
        //蓝牙连接成功后无法立即获取到服务内容，需要多次尝试获取，直到获取成功。
        setTimeout(function () {
          getBLEServices(_deviceId);
        }, 100);
      }
    },
    fail: function (res) {
      // console.log('获取服务失败! ' + JSON.stringify(res));
    },
  });
  // #endif
}
//
const senBleLabel = () => {
  // console.log('----------senBleLabel------: ', currDev);
  if (!ISsenBleLabel.value) {
    ISsenBleLabel.value = true;
    //标签模式
    // Enjoy.loadingHide();
    // MARK: - 记录打印日志
    // InputSumbit(gds);
    var deviceId = currDev.value.deviceId;
    var serviceId = currDev.value.services.serviceId;
    var characteristicId = currDev.value.services.characteristicId;
    var command = jpPrinter.createNew();
    if (IsUserDR.value) {
      var list = cmd.value.PrintDRlst;
      for (var i = 0; i < list.length; i++) {
        console.log('----------command PrintDRlst------------:', list[i].Command);

        command.setCmd(list[i].Command);
      }
    } else {
      console.log('----------command------------:', cmd.value.Command);
      command.setCmd(cmd.value.Command);
    }
    senBlData(deviceId, serviceId, characteristicId, command.getData());
    setTimeout(function () {
      //self.closeBluetoothAdapter();
      ISsenBleLabel.value = false;
    }, 100);
  }
}
//
const senBlData = (deviceId, serviceId, characteristicId, uint8Array) => {
  // console.log(432, '+++++++++++++++++++++++++++++++++++++++++++++++++', deviceId, serviceId, characteristicId, uint8Array);
  var uint8Buf = uint8Array; // Array.from(uint8Array);

  function split_array(datas, size) {
    var result = {};
    var j = 0;
    for (var i = 0; i < datas.length; i += size) {
      result[j] = datas.slice(i, i + size);
      j++;
    }
    return result;
  }

  var sendloop = split_array(uint8Buf, 20);

  function realWriteData(sendloop, i) {
    // console.log(455, '___________________', i);
    var data = sendloop[i];
    if (typeof (data) == "undefined") {
      return;
    }
    var buffer = new ArrayBuffer(data.length);
    var dataView = new DataView(buffer);
    for (var j = 0; j < data.length; j++) {
      dataView.setUint8(j, data[j]);
    }
    // #ifdef APP-PLUS
    plus.bluetooth.writeBLECharacteristicValue({
      deviceId,
      serviceId,
      characteristicId,
      value: buffer,
      success(res) {
        setTimeout(function () {
          realWriteData(sendloop, i + 1);
        }, 100);

        if (i >= (sendloop.length - 1)) {
        }
      },
      fail: function (e) {
        uni.showToast({
          duration: 3500,
          icon: 'none',
          title: '打印失败，此设备不支持!'
        });
      },

    });
    // #endif
  }

  var i = 0;
  realWriteData(sendloop, i);
}
//
const closeBLEConnection = (deviceId) => {
  // #ifdef APP-PLUS
  plus.bluetooth.closeBLEConnection({
    deviceId: deviceId,
    success: function (e) {
      // console.log('断开连接成功!');
    },
    fail: function (e) {
      // console.log('断开连接失败! ' + JSON.stringify(e));
    },
  });
  // #endif
}

const closeBluetoothAdapter = (callback) => {
  //closeBLEConnection(printer);
  //connId = "";
  // #ifdef APP-PLUS
  plus.bluetooth.closeBluetoothAdapter({
    success: function (e) {
      // Enjoy.loadingHide();
      //console.log('关闭成功!');
      if (callback != undefined && typeof (callback) == 'function') {
        callback();
      }
    },
    fail: function (e) {
      // console.log('关闭失败! ' + JSON.stringify(e));
    },
  });
  // #endif
}

// MARK: - 选择框点击事件
const clickRight = (type) => {
  if (type == 'c_store_id') {
    let parms = Enjoy.GetDialogParms();
    parms.CallBack = SelectionChanged;
    parms.SelectionType = "机构选择";
    parms.SelectedItems = mainData.value.c_store_id;
    Enjoy.OpenDialog(parms)
  }  else if (type == 'gdsLabel') {
    uni.navigateTo({
      url: `../modals/gdsLabel/index?c_type=2&storeId=${sUserStore.value}`,
    });
  } else if (type == 'printer') {
    uni.navigateTo({
      // url: '../../MainViews/user/setting/bluetoothPrinterSelector',
      url: '../../SelectorViews/bluetoothdevice/index?type=printer',
    });
  }
  
}

// MARK: - 上拉加载(下一页)
const templateUpper = async()=>{
  console.log('---templateUpper----: ', CurrentPage, PageCount)
  if (CurrentPage.value < PageCount.value) {
    CurrentPage.value = CurrentPage.value + 1;
    await getData(true);
  }
}

// MARK: - 下拉刷新(上一页)
const templateLower = async() =>{
  if (CurrentPage.value < PageCount.value) {
    CurrentPage.value = CurrentPage.value - 1;
    await fetchGds();
  }
}

// MARK: - 自定义折扣切换
const cutBtnClick = async() => {
  isShowSwitch.value = !isShowSwitch.value;
  // 清空折扣选择和新售价
  formData.value.newprice = ''
  formData.value.cutting = ''
}
// MARK: - 离开折扣输入框
const onBlurCutting = (e) => {
  if (e.newValue < 1 || e.newValue > 99) {
    uni.showToast({
      duration: 800,
      icon: 'none',
      title: `折扣率范围1-99`,
    });
    // 清空折扣选择和新售价
    formData.value.newprice = ''
    formData.value.cutting = ''
    return;
  }
  swichTab(e.newValue)
}
// MARK: - 离开新售价输入框
const onBlurNewprice = (e) => {
  const oldPrice = isPlu.value
      ? (pluData.value.plu_price).toFixed(2)
      : ((gdsstorePriceData.value[0].c_price_disc || gdsstorePriceData.value[0].c_price )).toFixed(2);
  const min = (Number(oldPrice) * 0.01).toFixed(2);
  const max = (Number(oldPrice) * 0.99).toFixed(2);
  if (e.newValue < min || e.newValue > max) {
    uni.showToast({
      duration: 2000,
      icon: 'none',
      title: `新售价范围：${min} - ${max}`,
    });
    // 清空折扣选择和新售价
    formData.value.newprice = ''
    formData.value.cutting = ''
    return;
  }
  swichTab( ((e.newValue/oldPrice).toFixed(2)*100).toFixed());
}

// MARK: - 切换电子称码规则
const togglePluMode = (value) => {
  pluMode.value = pluModeDict.value.filter(item => item.value == value);
  if (value == '0') {
    isWeightPrice.value = false;
  } else {
    isWeightPrice.value = true;
  }
  cleanGdsInfo();
}

// MARK: - 清空商品信息
const cleanGdsInfo = () => {
  // 清空商品信息
  gdsData.value = {
    c_gcode: '',
    c_name: '',
    c_barcode: '',
    c_price: '',
    c_model: '',
    c_plu_type: '',
    c_od_day: '',
    c_od_unit: '',
    c_type: '',
    c_status: '',
  };
  pluData.value = {
    plu_price: '',
    plu_weight: '',
  };
  formData.value = {
    newprice: '',
    c_dt: dateRangUtil.getLastToday()[0],
    cutting: '',
    number: 1,
  };
  gdsstorePriceData.value = [];
}

const closeCallback = () => {
  onfocusGds();
};

const onfocusGds = () => {
  // 控制光标跳转
  setTimeout(() => {
    RdsSearchBar.value?.clear();
  }, 100);
};

// 标题栏菜单刷新缓存回调
const onClickRefresh = async () => {
  // 删除模块内缓存
  service.removeStorageSync('条码规则参数');
  service.removeStorageSync('采购管理参数');
  // 清除缓存
  await clearRdsLocalStorage();
  // 初始化缓存
  await init();
  await getSysConfig();
}

defineOptions({
  name: 'DiscLablePrint',
});
defineExpose({
  SelectionChanged,
  onClickRefresh
})

</script>

<style lang="scss" scoped>
@import '../../../main.scss';
.main-info {
  display: flex;
  flex: 1;
  flex-direction: column;
  padding: 0 0 5px;
  border-radius: 12rpx;
  background: #FFFFFF;
  margin: $uni-spacing-row-base;

  ::v-deep .m-card-template {
    display: block;
    padding: 0;
    margin: 0;
    background-image: none;
  }

  ::v-deep .scroll-Y-list, ::v-deep .scroll-Y {
    display: flex;
    flex: 1;
    height: auto;
  }

  ::v-deep .m-list-template, ::v-deep .m-list-template-list {
    flex: 1;
    height: auto !important;
  }

  ::v-deep .m-list-template-image image{
    display: none;
  }

  .m-list-top {
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: 51% 49%;
  }
  ::v-deep .m-card-template-list {
    margin: 0;
    padding: 0;
  }
  ::v-deep .m-list-top {
    margin: 0 10rpx;
    padding: 0;
    display: grid;
    grid-template-columns: 51% 49%;
  }
  ::v-deep .m-list-content {
    box-shadow: none;
  }

  // 折扣 tab
  .switch-tab {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    background-color: #E3E3E3;
    margin: 20rpx 10rpx 10rpx 10rpx;
    padding: 6rpx;
    box-sizing: border-box;
    border-radius: 10rpx;
    flex-wrap: wrap;

    .active, .normal {
      display: flex;
      align-items: center;
      justify-content: center;
      border-radius: 10rpx;
      margin: 0 1rpx;
      height: 100%;
      padding: 0.2rem 0;
      font-weight: bold;
      min-width: 4rem;
    }

    .active {
      color: #000;
      background-color: #fff;
    }

    .normal {
      color: #515151;
    }
  }
}


.footer {
  margin: 0;
  padding: 0;
  flex: 1;
  display: flex;
  height: 100%;

  ::v-deep .m-card-template {
    display: block;
    margin: 0;
    padding: 0;
  }

  ::v-deep .scroll-box {
    height: auto;
    padding-bottom: 18vh;
  }

  .foot-view-item {
    overflow: auto;
    overflow-y: scroll;
    width: 100%;

    .m-list-top {
      display: flex;
      flex: 0;
    }

    .top-count > * {
      width: 50%;
      padding: 0 10px;
    }
  }

}

.bottom {
  display: flex;
  justify-content: space-between;
  flex: 0 0 auto;
  height: 70rpx;
  padding: $uni-spacing-col-sm * 2 $uni-spacing-row-sm;
  background: $uni-bg-color;
}

// start 查询筛选
.search-fields {
  width: 100%;

  .center {
    margin: 0 10px;
  }

  .search-field {
    margin: 5px 0;
    padding: 5px 0;
  }

  ::v-deep .m-card-input-content,
  ::v-deep .m-input-input {
    height: 100%;
    text-align: right !important;

    uni-view,
    * {
      margin: 0 !important;
    }
  }

}

// 列表项自定义
.custom-id {
  z-index: 1;
  position: relative;
  line-height: 1.2em;
}

.custom-id::before {
  position: absolute;
  z-index: 0;
  content: ' ';
  width: 2.5em;
  height: 1.2em;
  background: rgba(153, 255, 102, 0.2);
  top: 0;
  left: 0;
}

// end 列表项自定义

.virtual_head {
  display: flex;

  * {
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0 2px;
    color: #505050 !important;
  }
}

.virtual_head {
  border-top: 1px solid #e5e5e5;
  border-bottom: 1px solid #e5e5e5;
  // border-bottom: 1px solid #ffffff;
}

.virtual_footer {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 50rpx;
  gap: 10rpx;
  padding: 0 1rem;
}

.list_cell_item {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: stretch;
  align-content: flex-start;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;

  * {
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

.cell_color_code {
  text-align: left;
  color: #505050;
  font-size: 0.8rem;
}

.cell_color_id {
  padding-left: 0.4rem;
  text-align: left;
  font-size: 0.8rem;
  color: #3a8ee6;
}

.cell_color_num {
  padding-right: 1rem;
  text-align: right;
  color: #e64b3a;
}

.flex_w_auto {
  flex: 1;
  // background: rgba(110, 180, 40, 1);
}

::v-deep .list_cell2 {
  margin: 0;
}
// 重写虚拟列奇偶行样式
::v-deep  .list_cell_even {
  /* 为偶数行设置样式 */
  background: #f2f2f2;
}

::v-deep  .list_cell_odd {
  /* 为奇数行设置样式 */
  background: #ffffff;
}

.itemClickView {
  display: flex;
  width: 100%;
}
::v-deep .m-card-input-title {
  width:auto!important;
}
::v-deep .uni-date-single {
  justify-content: end;
}
</style>
